package com.dmall.opening.up.records.dao.mysql.mybatis.handler;

import org.apache.ibatis.jdbc.RuntimeSqlException;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LongTypeHandler implements TypeHandler<Object> {

    @Override
    public void setParameter(PreparedStatement ps, int i, Object value, JdbcType jdbcType) throws SQLException {
        long longValue = (value instanceof Long) ? (Long) value : Long.parseLong(value.toString());
        ps.setLong(i, longValue);
    }

    @Override
    public Long getResult(ResultSet rs, String columnName) throws SQLException {
        throw new RuntimeSqlException();
    }

    @Override
    public Long getResult(ResultSet rs, int columnIndex) throws SQLException {
        throw new RuntimeSqlException();
    }

    @Override
    public Long getResult(CallableStatement cs, int columnIndex) throws SQLException {
        throw new RuntimeSqlException();
    }
}
